﻿using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using Opalis.QuickIntegrationKit;

namespace LocalComputerSecurity
{
    [OpalisObject("Remove Local User")]
    public class RemoveLocalUser : IOpalisObject
    {
        public void Design(IOpalisDesigner designer)
        {
            designer.AddInput("Computer Name");
            designer.AddInput("User Name");
            designer.AddOutput("User Name");
        }

        public void Execute(IOpalisRequest request, IOpalisResponse response)
        {
            String userName = String.Empty;
            String computerName = String.Empty;
            userName = request.Inputs["User Name"].AsString();
            computerName = request.Inputs["Computer Name"].AsString();

            DirectoryEntry machine = new DirectoryEntry("WinNT://" + computerName);

            DirectoryEntries entries = machine.Children;
            DirectoryEntry user = entries.Find(userName);
            entries.Remove(user);
            machine.Close();
            
            response.Publish("User Name", userName);
        }
    }
}
